using Abp.Application.Services.Dto;
using HCD.Enums;
using Partner.Utility;
using System;
using System.ComponentModel.DataAnnotations;

namespace HCD.Messages.Dtos
{
    public class MessageListDto : EntityDto<Guid>
    {
        /// <summary>
        /// MsgTitle
        /// </summary>
        [Required(ErrorMessage = "MsgTitle不能为空")]
        public string MsgTitle { get; set; }

        /// <summary>
        /// MsgContent
        /// </summary>
        public string MsgContent { get; set; }

        /// <summary>
        /// MsgType
        /// </summary>
        public MsgTypeEnum MsgType { get; set; }

        public string MsgTypeDescription
        {
            get
            {
                return MsgType.GetDescription();
            }
        }

        /// <summary>
        /// MsgDateTime
        /// </summary>
        public DateTime MsgDateTime { get; set; }

        /// <summary>
        /// SenderID
        /// </summary>
        public string SenderID { get; set; }

        /// <summary>
        /// SenderName
        /// </summary>
        public string SenderName { get; set; }

        /// <summary>
        /// FeatureID
        /// </summary>
        public Guid? FeatureID { get; set; }

        /// <summary>
        /// Url
        /// </summary>
        public string Url { get; set; }

        /// <summary>
        /// FeatureTitle
        /// </summary>
        public string FeatureTitle { get; set; }

        public bool IsRead { get; set; }

        //// custom codes
        public string ReceiverNames { get; set; }

        public string FromNow
        {
            get
            {
                int year = DateTime.Now.Year - MsgDateTime.Year;
                if (year > 0)
                {
                    int month = year * 12 + (DateTime.Now.Month - MsgDateTime.Month);
                    if (month < 12)
                        return month + "个月之前";
                    else
                        return DateTime.Now.Year - MsgDateTime.Year + "年之前";
                }
                else
                {
                    TimeSpan ts = DateTime.Now - MsgDateTime;
                    if (ts.Minutes < 60 && ts.Hours < 1 && ts.Days == 0)
                    {
                        if (ts.Minutes < 0)
                            return "0分钟之前";
                        return ts.Minutes + "分钟之前";
                    }
                    else if (ts.Hours < 24 && ts.Days == 0)
                        return ts.Hours + "小时之前";
                    else if (ts.Days < 30)
                        return ts.Days + "天之前";
                    int month = (DateTime.Now.Month - MsgDateTime.Month);
                    return month + "个月之前";
                }
            }
        }

        public bool NeedAudit { get; set; }
        //// custom codes end
    }
}